version 4, faster computation