some code fixes and clean