Added some logic and turned some tables into classes.