some minor code deduplication