Updates for efficiency - was doing unnecessary checks and creating unnecessary arrays.