Include stdlib.h in files where its functions are used

This fixes compiler errors when compiling on OSX via terminal (and maybe on other systems that I can't verify).

(Ignore the reverted commits, they weren't meant for this branch)