replaced array push() with temp variable