Key detection improved / ui.py cleanup