Latest code after 4th's initial solution.