[refac][fix] makes the library to use less stack memory