refactored and comprehensive tested queries and cursors (closes #2)