cleaned up controller code, small reorganizations