Refactored DB access code and added flags for json parsing