Tidied up model/sql. Next up, tests!