Split up code, added data access layer