Organize code a bit better and implement query_interface.