Fixed a very evil deadlock, and cleaned quite a bit up in core