Added a wrapper function and first attempt at exception handling.