Added comments and some polishing