remove unneccessary code and fixed some bugs