Refactored DB, server and JSON code out of main service