bad recursive attempt at gates/keys