Rewriting "stargate filling" code in a nicer way