Fixed it, much cleaner now using exceptions instead of special case logic to avoid the runtime error.