despite the large changes, this commit only moves functions