More minor improvements
Rearrange the code to make it clearer
More code simplification