Format, and switch more code over to easier testability.