added parameter statedir for easier configuration