Working Code

Final code that implements both functions