Added error checking and extension checking