updated code for synchronizing matlab job