Also, no docstrings or pre/post conditions in here so it's difficult to figure out what's going on.