refactor extract function
remove unnecessary logic
refactor use conditional operator instead of if statement