Added a check to prevent NullPointerException which fixes #1, this exception DOES need to be handled on a higher level.