cleanup, fixed some bugs