moved all code and calculation to an external library