Continuing code cleanup, there are bugs still in there