fix abort regression and refactor a bit of code