Fixed all of the methods and added some testings in the main method.