Refactored array generation

Before the code was totally borken if the object passed in was a member variable of a class. It now works.