Removing empty for-loops in some cases