Merged onerun fix and added mutex to prevent segfaults