refactor if-else statment logic.