Added comments and removed unnecessary and unused code