synced with Georgs queries
fixing bugs and adding transaction functionality