refactoring the way keys are applied. Adding more documentation.