cleaned up/optimized code. added RW bit support and write abstractions.