More refactoring and eliminating sql-like things