found a couple bugs in the code and fixed