Restructured and added functionality