Moved a few function out of the closure of scpromise to be a bit more memory friendly