update the code by david