got rid of static variables. pass by ref instead