update logic to make it more readable.