rewrite this with `switch` for better readability.