Fixed several bugs

Fixed #10 #11 #12