Function keys and some refactoring