Fixed bug where write length was compared aginst a constant instead of the varaible being written.