Separated files and fixed loop