Major cleanup. Seems like things work