Fixed printTo function to return a length