Further simplification and fix a bug.