use defer as Nigel suggested
Added comments based on feedback from Nigel
fixed out of date comment pointed out by Sameer
added Sample test
remove stale code
simplify and speedup Sample