Changed logic to use delegates instead of blocks