Refactor prefill for testing (#166)

Modify the prefill script so that it can be require'd and used elsewhere (in testing scripts, for example).