Refactored a little bit to use array.push(), saves a few lines of code and is easier to follow.