major modification and fixes