fixed global assignments problem, improved functions working together