Implemented the necessary functions for the assignment.