Moved deletion of pid file to finally block