Improve Lab 1 Q4 solution
Format code for clarity