Break down the spaghetti function a bit