improving sql operation functions