Various bug fixes #2