This might fix issue #26. Thinking about sorting does my head in though.