fix rdwr bug, add unit test