More robust algorithm for inner classes. Still need clarification before solving issues #15 and #18