Various improvements and fixes