Fixed various bugs.

still pretty bugged.