Fix bug where delays >1sec caused crash and moved printf to after nanosleep