Came up with a better m/d algorithm