moved query logic around - TODO: make async calls work
Added factory method for class instantiation