Fixed up subprocess issues

Re-worked logic to be more sane
Fixed thread locking bug