pack samples and refactor code