Cleaner code, loop through dimensions instead of manually