key generation security & layout fixes