ported #30, #29, #39