copy recent code, few fixes