Close handles and terminate processes

Trying to fix the "resource exhausted" problem.
Add margin to bottom