Old code had a memory overflow bug and also new approach is cleaner.
Important: I left some code that needs to be cleaned up but shouldn't
interfere with new approach. I left this code for now as I was worried
that I may not remove it appropriately. More info in comments.
Additional notes: I don't have environment so didn't compile it even once so there might be some obvious errors like missing colon. I hope it will work 'as is' even without further clean up.
Old code had a memory overflow bug and also new approach is cleaner.
Important: I left some code that needs to be cleaned up but shouldn't interfere with new approach. I left this code for now as I was worried that I may not remove it appropriately. More info in comments.
Additional notes: I don't have environment so didn't compile it even once so there might be some obvious errors like missing colon. I hope it will work 'as is' even without further clean up.