Implemented both functions for exercise