Refactored guard clauses to use ArgumentError and exception handling and made code more DRY