Refactored model, added database support.