Improved function return values

Now checks for an empty vector in the case of an error