Various improvements (thanks @dimanux)