Move logic into a package.

Change-Id: I8795a746c10295e76a32668ed034d308074cab14