First working version. Data format is very complex, needs sorting.