fix #146 #148 thanks to @https://github.com/brianchance