cleaned up code

changed strategy for detecting module instance