Added additional error checking and additional defaults