some (very) small performance improvements, now using exceptions for error handling