Split out controller and viewmodel code