Added a few comments and a if() to prevent a nullpointerexception.