Bug fixes #36 #37 #26 and #27