fixed not using the passed in length