changed switch and fixed some bugs