redesigned some functions