Added better error handling to _kwargs() and added doctests.