keypath code refactor