store: add test and fix various bugs