More refactoring - moved API validation into api.py, moved queries into query.py