slight modification of the demo program per the teacher's request
fixed fence synchronization