Cleanup and migration to the newest riak_core aae code
Some more generalization.