Implemented direct-instances function

Incorporated direct-instances function and updated minor direct-subclasses code duplication. 

PR split into two as requested.