optimizing code and adding keyboard