Sorted out the resizing bug by redoing the logic in the function.  close #340