Some performance improvements I hope
Some query optimizations, still too slow