adding index and fancied up the error returns