move sc logic out of tasks.py