updated code to handle multiple formats