added key listener/cleaned up code