replacing assert with Exception