huge overhaul, fixes a lot of the bugs.