code clean up and necessary comments added