Problem 50 solved and a bit of cleanup