Added comments and removed some unused code