Fixed dead-lock code to actually work...