lots of changes from original version