reorganized some functions