change logic from top to down