refactored lots of code
most of it was after automatically code analysis