Maybe better to take in the length as a parameter? (lengths > 255 will currently unexpectedly go wrong)