updated using DRY principles-ish