Changed to use semaphor etc.