picking code in better condition but still some bugs