porting 162a8d5793c6f897a42d93af70ff6db05226f61e from forestv