Reorganised code, added crypto + tests
Remove trailing whitespace