updated code for better reusability