Issue #52 & bug fixes