fixed mysql queries and loading order