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