The present invention provides a compound of Formula (I) and stereoisomers thereof, and pharmaceutically acceptable salts of said compounds and said stereoisomers, and pharmaceutical compositions thereof, and methods for using said compounds and compositions for treating or preventing thromboses, embolisms, hypercoagulability or fibrotic changes. The compounds are selective Factor XIa inhibitors or dual inhibitors of Factor XIa and plasma kallikrein.