refactoring to get rid of space bar bug