implemented issue #37 and #36, but #36 needs to be tested