Refactoring stars with loop from if statement