Fixed priorities and added error handling.