Fixing issues #18, #19, #20, #21 and #22