vid 33&34:
more code refactoring
added to query function