Separate helper function impls out
More bugfixing