refactor subscription management code