Working expansion algorithm

WOOOHOOOOOO