if length < 4 this won't work.
also you should return what's left of the input.