Reduce code redundancy as suggested by @mwiencek, add a test case