fixed and optimized 'linker' function