Fixes for issue #1 by @berak