Added database and refactored tests