Arranged codes and added comments