added callbacks, reworked query