Thinning node

All known bugs have been fixed and code has been cleaned up - ready to merge.