Hopefully fixed helper function detflower