refactoring to make better use of existing npm modules