Bug fixing under umbrella of #19 and #15