Condense / speed-up some of the code by using array lookups