Initial, buggy version (sometimes hangs)