Fixed exception handling