Move env maintenance using a gen_server / ETS

This a standard technique to maintain some stateful application configuration:
an ETS table owned by the supervisor + gen_server communicating with it.

This removes all the nasty hacks needed for cleaning the application env when
stoppin and guarantees that restarting the application will always give you a
fresh state.

Also, added some more tests.