passed variables by reference and that did the trick