Removed code duplication
Merge pull request #393 from WouterJ/improvements

Removed some code duplication