Moved success function around for readability