updated functions and fixed bugs