added memory locking to prevent random crashes