Fixed bug with length checking