Fixed closing of pid file