Refactor to move primitives processing in its own file.