Used tuple algebra to simply code. Used loops to tidy it up.