Added some typing, imported external linking and moved some functions.