Abram's original code (with minor directory mods)