added ajax functionality thanks to Tony