Fix if/else-bug, add unit test