fix undefined len and reverted to using instance variables directly