Simplified here: https://github.com/chuckharmston/zamboni/commit/a02f135764f20c508b880fc06f267d1cda479535#L1R87