Personally, I think it's probably a bad idea to sell your code, since you lose control over it. IANAL, either, but it seems to me that you could wind up getting sued for using code you created yourself, if you sell it to someone and then try to use the modules, even if you recreate them. Chance are, the code will look similar, which might leave you vulnerable.
Probably the best suggestion is to talk to a real lawyer if you can afford it. Especially if you can afford it, because that makes it more likely that suing you would pay off.