fix bugs and code improvements (yes again :) )