added some tests and refactored controller somewhat