Adding special function for direct sql query. Code refactoring.