fixed bugs, added new code