Added Key class and refactored