This needs to be split into a fix and a cleanup. Attached is how I'd do it.