Fixed formatting, added closures, added a lock around native functions