Better key handling (and fixed indentation)