Cleanup, fixing some bugs