refactored all sql to a separate lib file