Stack overflow problem fixed