Added a distance factor to lighting

also removed spaghetti code