Refactored method and moved to lib