a little code redesign and a few bugs solved