several bug fixes, #10 #13