original codes from Chirs