merged upstream but reved local changes
reimplemented rebanip function