better exception handling for invalid references