Finished switching functionality.

I need to polish it and rewrite comments, but that's fine.