Tested and fixed special cases.