Adjust the structure for easier new handling functions. Also add more tests.