refactored the code for both lib and angular