fixed samples and refactored code