Upgrade lib and make some minor improvements