complete query and start adding tests/javadoc