Take points calculation from php code

This is basically just doing what the php code looks to be doing. @henare can you please check over this and do a sanity check. This also fixes #224
Wow, that's really sloppy work of mine :(