made some changes to functions and added main prog