the calculation below should be put into a separate function, I think