Clean up code and remove ternary-if operation