change output and add backtrack removal