updated with another student solution.