Refactored code in database connection and RestHandler