made it so folder for logs is created if required, changed query