bug fixes

#14, #15, #1, #10, try to fix #11