suggestions

That’s only superficial stuff; I couldn‘t dig deeper into the code because I don’t have a test file. Could you post a short snippet and maybe an image of the intended result?