Fix linking and do some minor changes