Calculate tax algorithm