fix bug with plan update when unsubscribed and refactored some code