new file arrangement and clean up
move logic to jslib