made some changes - this may be totally correct