Add normalisation, fixes #5.

Refactor a lot of code.