Fix optimization

Optimized the return value calculation on arrays. Which were already set
to numeric. Moved the regular expression out.