bug fixes, complete sample