Added conditions logic