port code from WFLY master