pasim: replaced downto loop with nicer loop