minor re-factoring code to align with suggestions from the solution