Issue 487 db

This is ready for initial review. Thanks.