Some small db query optimization and put comments