Fixes issue #39, issue #40, issue #41