main function of library works, but needs tweaking