optimize code for split hash by key