Fixed problem iterating through loops to call density subroutine