Conditional inside loop patterns

Removed several branches which may be performance bottlenecks, please review