Updated the class by adding Java Doc and better error handling