Cleaned up code a little. Added functions which don't canonicalise.