modified sample codes in more details