Fixes issue #55 with code from jnhwkim.