Code simplifications and minor improvements