updated classes to handle NullpointerException and add comments