bug 1316: rework on calculation
bug 1316: Shorten the code even more and make it much more readable
Merge branch 'bug-1316' into testserver-stable