Refactored loop and made it more Ruby like

Signed-off-by: Kristof Kowalski <kristof@kowalski.ms>