Added comments and solved NullPointerExceptions