completely rewrited, changed variable names, added new function definition
Changen function name