Fix for stack overflow on non-static inner classes

Fix for stack overflow on non-static inner classes issue discovered by Antony Stubbs.