Clean up implementation a bit.