Fixed logic for removing last comma