Refactor code with better method