Refactor preferences window