per-period statistics
fixing tests
refactoring error handling