Function made out of code.
Comments added