The Secrets of Consulting: A Guide to Giving and Getting Advice Successfully by Gerald Weinberg
tl;dr (but really, read it): it's about the people, not about the code
If you want a contract, here's one that someone gave me years and years ago. I never had it vetted by a lawyer, so YMMV, but it is clear enough about the important things. https://www.mooreds.com/standardContract.html The Nolo books have contracts too.
I'd advise hourly billing and weekly or biweekly invoices getting started. There are lots of options but that is the simplest one for both sides.
"The Secrets of Consulting: A Guide to Giving and Getting Advice Successfully"
"More Secrets of Consulting: The Consultant's Tool Kit"
These books kept my sanity and showed me the Universe twisted
sense, twisted...But nonetheless a sense.
For larger firms though you won't get in without middleman (because of preferred supplier lists (PSL)). The bigger players pay you usually competitive rates (unless the middleman is fucking with you which is rare but happens), but you won't own the relationship with the client (the middleman does). Work for smaller firms and you run a higher risk of losing money, not getting paid or getting shafted simply because they think they can.
Ask a lawyer to help you draft contract templates which reflect how you envision any business relationship and then make your clients that you work for directly sign that (rather than expecting them to talk to their own lawyer which the won't do if they never considered bringing in a freelancer).
Find other freelancers in your region to speak to and get a feel for what they charge and how they go about acquiring new clients.
Biggest question when pitching to middlemen is "do you have any freelance/consulting" experience. If no this will be a read flag. So be creative to get your foot in the door.
Ensure you stay on their radar: Send your professional profile to every middle-man in the country and keep updating them with the latest version and your current availability.
Always say yes to any opportunity when asked for an interview (even you're busy right now with something else, or it is slightly off-topic for you). It's a chance to network and to practice your pitch (practicing the skills of interviewing and marketing your skills/brand is even more important than knowing your technical stuff, the latter should be taken for granted).
Gerald M. Weinberg's "The Secrets of Consulting" is excellent for anyone starting out in consulting or for those who consider hiring them (in any case your world might never be quite the same after reading this book):
It's a bit like diplomacy for engineers.
for those not familiar with Weinberg: https://news.ycombinator.com/item?id=17716098
1. Client education, AKA managing expectations. Educating the client on the principles and challenges of software development. Most know very little about this and it makes their job very frustrating. Every failure of consulting is really a failure to manage expectations.
2. Communication. How are they communicating, what are the problems? This is the most important thing in software development (and business in general).
3. Methodology review. How are they managing the project? What methods and tools are they using? Are the tools configured, integrated, and automated correctly?
4. Developer practices. Mostly based on my programmer productivity talk.
You are focused on #4 (and some of #3), which is important, but I find the first 3 way more important for "success." #2 sounds like your biggest problem. When I hire developers (always 100% remote) I prioritize two things: communication skills and discipline.
I'll give you one tip: static code analysis tools. This way the tool is criticizing the code instead of you (of course, I agree with code reviews). When I realized how useful this is I started giving talks on it.
Also, Gerald Weinberg's The Secrets of Consulting is gold: https://amzn.to/2JvDZnx
There was another HN thread some years back linking to a fascinating blog post of somebody who pointed out not to charge hourly rates and invoice per week. It was giving really solid advise on pricing strategy for individual consultants to increase the rate from 100/hr to 6-8K/week. It argued to never compromise on the price but see what parts of the project could be left out, etc ... If somebody here remembers this site/article it would be fantastic (I can no longer remember where to find it unfortunately).
It sounds to me like contracting is worth exploring. When I contracted (for about 7 years), I was exposed to new technologies and business domains every couple of months. I fondly remember about 2 weeks into every contract there was an 'oh sh*t' moment where I realized I was in over my head and running to keep ahead of what the client needed. Of course, that was nicely counterbalanced by the 'aaah' moment about 6 weeks in when things were finally jelling.
(I mostly worked on custom web applications and ecommerce and made a decent living working 30 hours a week.)
If you pursue this path, you might want to consider going out on your own as a single person consulting company, rather than going through a contracting company. You'll have more control, though less security, and will have a wider scope of project domains. That said, if you are interested in certain types of projects (J2EE, big data) you might find it hard to contract as a one person show.
Of course, I don't know what your financial situation is, but if you pursue this, I'd start going to meetups, have about a year of expenses saved in the bank, and read a couple of good books like this one: http://www.amazon.com/The-Secrets-Consulting-Getting-Success... and this one: http://www.amazon.com/exec/obidos/tg/detail/-/027363707X/002...
At best you might start up an independent consulting firm, but you'd have to have multiple clients and spend a lot of time on sales and marketing (of yourself). Gerald Weinberg recommends you make your hourly rate 5-6 times what you want to earn just to allow for all the overhead (http://www.amazon.com/Secrets-Consulting-Giving-Getting-Succ... or get it new from the publisher: http://www.dorsethouse.com/books/soc.html).
Fresh book recommendations delivered straight to your inbox every Thursday.