Refactor to use sn as globle variable