modularized code, added keyboard functionality