Fix for rag cutting segfault + tidy up

This is getting ridiculous.