almost all implementation done for library (img2term)