add casting error handling