implemented the whole thing again, with better stuff