fixed bugs, works but outcome poor