Refactor makekeys with some convenience functions All the nested ifs in the parsing code were confusing me.