adding support for refs, almost code complete, bug with ref arrays