Simplified code slightly

Also, plan on adding key code (see comment)