Fix some swift problems

DO NOT MERGE YET
* fix get_or_create_sp() that may cause a dead lock