Moved global vars to config, +some minor bugfixes.