Completed assignment by implementing two functions