Added more useful exceptions and removed redundant checks.