1st working attempt at both functions