Some refacotring and reorganizing