Various fixes and reorganizing