Bugfix when ending set is empty, refactoring