modified busy wait to use sleep instead, should be much nicer on cpu