Cleaning up code, fixing nexting and handleError stuff