Add tests

This refactors some of the helper functions that were in the controllers module, and makes the application more testable. 

It also adds a couple of tests for controllers, including one for sanitization of regex, which were causing application errors up to now.