This paper has been withdrawn. It will be split into two separate papers. New results will be added in both papers.