Updated add() to increase array capacity when required.