Refactor code to put it in libs.