Further performance tweaks
Added temporary arrays and type annotations