Storage refactoring

Tests and other fixings
Merge branch 'refactoring'