Improve querying
Remove unused/tested code