More modifications and clean up of code