fixes issue #5, #6, #16