Reorganized some functions