fixes from broken branch, addition of prev argument