fixed a subtle bug in storage and added more unit tests