Closes issue #83 and #82
Thanks to zamalaev