Bug fixes

Fixed #30
Fixed #29
Fixed #28
Fixed #27