Restructured and added tests