Implement simple CommonJS spec
refactoring code & clean up