added a lot of stuff. shri's changes rebased on master.