now have separate temp and permanent folder

also cleaned up the code a little bit