added missing brackets
added debug logging