Refactored code. Added Base classes for sql generation.