Re-wrote most code.