fixes: #20 #32 #40

fixes #20, #32, #40 
and some cleanup