varous improvements, thanks Alex Bush