Move database queries to model
Update with new API
Move file management functions to files module