implemented query input and some minor cleanups