templated to work even with empty database