Fix linking isues and wrong variable initialization