Abstract db away from views; fix tests