Hardeded the query handling a little bit. Added some undefined checks so the query object is a little more flexible.