Implemented the main function and two other funtions.