Fixed valgrind error with nanosleep