Changed order of wait and synchronized