Major Overhaul

major overhaul.

previous implementation was mutable so it was going to be way to
difficult to test.