Fixed issue #114 and #135

Needs big comment block here to explain the purpose of this.