Restructured some functions