refactored to freed + setAs to work around #2660