more updated version from code