compressed the many conditionals into two simple math operations