Refactor writePrimFixed and writePrimBounded