improve the code for calc plugin