Properly unregister dynamic permissions, moved event listeners around