Added a database helper class, got rid of redunant code (refactored) and added more comments.