Almost complete first part (just to solve the condition variable issue)