prevFile.stat was null sometimes, needed a check for that. Broke out the if statements for now so it's easier to follow the logic.