refactor for key parsing