Added finishing touches on main function.