factorial with exceptions added