refactored get_samples method removing duplication