Fixed WG autopurge, some small refactorings.