Clean-up the implementation a fair bit.