working on sql test coverage and code refactoring