important sampling implemented
write to file fixed