Refactor parsing functionality.
Significant refactoring to make module easier to use.
Removed unnecessary dependency on optimist module.