Optimized array code

This may or may not compile, so I left the old code intact.