1) added rwlock function
2) added error return