semi-working version with shelve