Removed too much SQL from models and moved it to functions on db.php