deleted redundant code

this is an improved version of the sample which removes redundant code