refs
Simplified Peter's code.