refactoring and first stab at perennial mode