refactoring to remove premature OO
write balance cache