refactored code a bit. used C++ references whoa