Adding some checks and defaults.