Develop afishyfez

Alright I'm giving this another go. I'll be honest, I've no idea what I'm doing but let us give this a shot!
This function seems complicated and hard to follow, can it be simplified? There also seems to be some dead code.