Added some logic as to what runs when