Refactor and improve some files