refactored to look more like node API + added npm / require support