Fixed #76 and #73. See http://blog.rdcy.de/?p=279 for more details