Reworked the processing of the input, but its still flawed. See comment in the source.