Added delete funtion on key press. Cleaned up code