Refactor switch to if for readability