finished algorithm somethings wrong
COMMENTED OUT MEAN SUBTRACT