Add tests, reformat code