Added 'stopOnError', fixed some refactoring bugs