fixed bugs, added to function