Code refactoring & improved Node.js compatibility 

- Code was slightly refactored.
- Improved compatibility with Node.js's `require`: in case when module is not defined throwed error is same as in Node.js (messages and code properties are identical).