have you tried the terminal command caffeinate ? (see man caffeinate)
for example, (if you are running on a/c power) and type this into terminal
caffeinate -s
you can close the lid and it won't go to sleep. To stop it and allow sleep again just enter:
ctl-c
Add the & character to the end of the line and it will spawn a subprocess to run caffeinate which allows you to continue using the same terminal window for other stuff, although it's probably best to just use another tab for that so you can come back and stop caffeinate easier when required. The best thing is it's free and works on any version of macOS.