changing billing/subscription logic from partial pseudocode to working