Add global error handling in Utility

Split testing code to TestMain