BIG refactory, cleaned up debug messages, made easier to configure with config files