made code DRY-er