Built js functionality

partially refactored