Finished logic and removed an error when calculating the transition