added cleanup and final chmod