added comments and removed dead code