Mostly ported to Chicken 4.7.x