This method seems to do a lot of different things. Maybe divide it up into the "insert" part and the "get order" part.