Refactor code and add celery