Fix some bugs. Drop some unused codes.