some tweaks and fixes to d417f7b and 3dcbbc2