some optimizations around code that code climate reported as complex