Re-engineered almost from start (checkout unit tests).