Restructuring, small fixes