Monster merge. Will need to clean up some more later.
Clean up with fixes post merge.