Added back installation of dependencies
Allocate the memory outside of the loop