Adding some tests and moving out db calls to models