Refactored some stuff, adding link functionality

Trying to not to resort to globals