Refactor some utility functions into a separate module; add unit tests for utils and collector functions