I believe the error has something to do with the way Ending is defined, as when I comment that out and hardcode a value it runs fine.