Factorize builders

This PR implements what discussed in issue #990.