Bug fix and combine the function.