fix some subtile bugs