Add more error checking in config function