moved the code around so the important part is at the top