added tests and minor refactoring of the celery task