Fix various bugs in support functions