Refactor shared code between bits into a library