Added early termination + bugfixes