Fixed some array casting issues.
Handle variable type usage better.