finding optimal structure