Add validity checks and DRY