added database schema name to the sql query
created functions for inceased code readability
get rid of some warnings