major refactoring sql classes