code slightly improved