rebased and made some corrections