added updating functionality and cleaned up the javascript