add lots of refactoring and helper.js