Adding in defaults handling (Tim Sutton's code).