Refactored and redesigned some stuff with DB in mind.