support priv dir, refactor a bit