Complete rewrite. Good to learn new things.