fixed sync function for command line usage