Made some changes to give this more structure