Update javascript for collections

Updated the javascript based on feedback and implemented the TODOs.

@jmclean and @Stof could you please review the changes, thanks.