DRY some code

(Don't Repeat Yourself)

I just took the liberty to remove some repeated code.
For the future, it will be a good idea to have tests around this, so I can feel confortable refactoring this code.