correctly handle -1 errors
some order for this func