consolidation of js

added new features and consolidated old code