Some tweaks on main function