Not the most elegant way of doing it, but better that seeing InvalidOperationException