Bugfixes for #30, #33

Thanks to baquilla