some codes from jdon.com