Completely refactored database interactions (#19)