Adding some logic that seems to be working