Moved and commented some code. Optimized star bkg generation