Some performance improvements removing some unnecessary db query