Restructured and added functions