reimplmented for-loops