first attempt and simulate function kind of working.  Small errors to be fixed