added target function and fixed bugs