merging #32 with minor changes