factor a small bit of code out of base.js