code refactoring
add keyboard handling