Reverted move of function in to wrong lib. A little better API error checking.
A little better API error checking.