0 instead of 1 given if S = {1}; also int changed to float
changed data structure