Version 2, with work in loops