added waitkey code to allow break