working RMA code, needs documenting