Fix #321
Fix #319
Fix #322