added query and matrices implementations