Optimize factory function

With this change, `randomColor` no longer redefines all of its helper
functions each time it runs.