fix some corner cases in the build setup and loop
improved API documentation