Restructing and minor fixes