Simplify everything and add some tests