Fix some bugs and clenup