Moved stuff around, consolidated code