Seems like quite a bit of code duplication in this file now.