Separated things and added comments so the code is easier to read