AOP: clean up implementation and add tests.