Error propagation to JS, fixed a memory leak