Fixed error on corner cases