fix compilation errors / tiny improvement to toJs