code refactor for better implementation