internal code for #79