Add  a null check on connection - you rely upon it not being null later in the code