cleaned up mysql queries slightly