reworked to execute under vanilla sh