rewrite with my own code to make it make more sense.