undefined index fix

main checks for -1 result