Fixed models, added test, added sql