Fixing "Sleeping code"