Fixed Issue #365. Added test