I didn't want to replicate the whole code block in each `if ... else ...` therefore I put it in a function.