exception handling to prevent crashes