better logic, issue #6