combining steps 3 and 4 clean code and write