Port from rev 561