Compressed the many conditionals into two simple math operations