Controller has been refactored to allow unit testing of it.