More simplifications and extracted key function