Some optimazations and reorganizing