Added database handlers and refactored some stuff.