fixed bugs and improved program