added checking for close bracket as well