refactoring for apache review, https://reviews.apache.org/r/16322/