added utility function & refactored