Fix bug #10, #11, #12, #13