Bug fixes

Also added additional features.