refactered functionality and created calculate rule using mathjs