Fixed linking

Sadly couldnt test this, maybe its broken maybe its not but if I get the logic of the code right based on my memories it *should* work. Some day when i get the time ill sit down and rewrite all of this mess. [/rant]