Add storage unit test and fix bugs that it revealed