final work on main function, testing and modifications