add better query interface
split into separate files