Changed if logic to make it nicer