Finished coding for both functions