Check errors in sample loading

Also simplify sample indexing when possible.

Signed-off-by: Claudio Matsuoka <cmatsuoka@gmail.com>