added some input checks (via try/catch for speed)