sample fixes, refactoring