Fixed error checking the length