refactoring functions, replacing if/else with ternary where applicable