Added comments and removed unnecessary code pieces.