Added nanosleep to prevent the use of 100% CPU