bug fix #4 and general enhancements