adding library and some bug fixes