some errors corrected in the code after testing using JUnit