All keys in main moved to separate functions