Cleaned up code in database handler