Corrected the selectall_arrayref function call and added some error handling.