improved code from already existing package