Suggestion of code reformulation

I made a few changes to improve code.