move x key handling code into own function, maybe move into x utility file next.