Major Refactor

Seems to have an execution bug in it.