Refactor JS
MInor bugs