Added code for both functions