Added codes from Andy

Provide by Andy.