Refactored util function and moved to common util