Code cleanup. Initial key handling.