Some fixes, restructuring, formating