Updated design and made the javascript more robust