So I wrote a system for my job and now I want to write it from scratch so that I have my own copyrighted version in addition to what I've done for my boss, which does not belong to me of course (pay for hire). The problem is it is very hard not to follow the logic/algo flow from some parts of the code. Some methods will end up having the same flow, even though there will can many improvements and differences, changes in variables, changing in strategies, additional IFs to check other stuff and many other features implemented on top of it. However, I'm afraid that no matter what the basic underlying core logic is similar.
Because I wrote this thing myself, it becomes even harder to come up with a different approach to code the same thing. I like what I did for my job so improvement on top of this by departing from my original API approach sounds bad.
So my questions are: is there a way to rewrite what I wrote for my boss without infringing any plagiarism or license terms?
Let's assume I'm not checking my boss's implementation that I wrote because I quit my job but because I wrote (and because I have a good memory) it is all in my head.
Is there a legal workaround for that situation? Are algorithms protected by copyright?
So if you wrote something for your boss, you have to be very careful for the both versions not to look somehow similar. At least the algorithm and the logic flow ought to be similar.
What should I do? Any positive words of wisdom?