made some changes (not all of them work) from harshad's repository