optimize code & update example