Changed around calculation to try to speed it up