reformatted update ajax code, removed duplication