found some potentially serious bugs in RW class (should not affect results but needs to be tested)