Improved error reporting
Added standard JS implementation