changing logging; changed global variables moved some functions