Replace excess code by appropriate library. Add libs.