Fixes several bugs. Add avoid redundancy.