It should be fairly straightforward to do and it's more robust in the face of arbitrary input.