Added some checks and cleanup to challenge4