Added nanosleep call to prevent CPU hogging.