Skeletonize

Fixes issue #489 and some minor code improvements