Several improvements and fixes