Enhancements and bug fixes

Thanks @JeppeTh !