refactor and add keyboard input too