Replaced assert with Exception