Improved locking

Make the locks smaller, only lock on the actual native calls, not on any resulting operations.