Fix some issues with sample start/end being incorrect
Prevent a potential SEGFAULT.